# -*- coding: utf-8 -*-
# Author: xiantingDeng
# Email: dengxianting@shxgroup.net
# Time: 2020/8/6 17:58

import os


def get_device():
    '''
    获取设备名称和版本号列表
    :return:以列表方式返回设备信息
    '''
    device_name = ""
    device_version = ""
    cmd_device = "adb devices"
    with os.popen(cmd_device, "r") as f:
        for line in f.buffer:
            if "\tdevice" in line.decode(encoding='utf8'):
                device_name = line.decode(encoding='utf8').split("\tdevice")[0]
                cmd_version = "adb  -s {} shell getprop ro.build.version.release".format(device_name)

                with os.popen(cmd_version, "r") as f:
                    for line in f.buffer:
                        device_version = line.decode(encoding='utf8').strip()

    return (device_name, device_version)


def get_device_model():
    device_model = ""
    cmd_device_model = "adb shell getprop ro.product.model"
    with os.popen(cmd_device_model, "r") as f:
        for line in f.buffer:
            device_model = line.decode(encoding='utf8').strip()

    return device_model


if __name__ == '__main__':
    print(get_device())
